Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin infra for adding new dashboard tabs/cards #1742

Merged
merged 1 commit into from Jun 26, 2019

Conversation

rawagner
Copy link
Contributor

@rawagner rawagner commented Jun 18, 2019

@openshift-ci-robot
Copy link
Contributor

Hi @rawagner. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 18, 2019
@spadgett
Copy link
Member

/approve
/assign @vojtechszocs

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 18, 2019
@spadgett
Copy link
Member

/ok-to-test

@openshift-ci-robot openshift-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 18, 2019
@spadgett spadgett added this to the v4.2 milestone Jun 18, 2019
@rawagner
Copy link
Contributor Author

After discussion with @vojtechszocs I changed this a bit - adding tabs and cards is a separate extension. I also improved types a bit.

position: GridPosition;

/** The card component to render */
component: React.ComponentType<any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @spadgett @christianvogt

Directly referencing a React component from within a plugin's entry module will make it part of the Console initial chunk, which is already too big.

The default strategy for referencing plugin-contributed React components should be

Promise<TypeOfComponent>

and using either

() => import('./path/to/module' /* webpackChunkName: "chunk-name" */).then(m => m.MyComponent)

or

async () => (await import('./path/to/module' /* webpackChunkName: "chunk-name" */)).MyComponent

to provide those components.

Please add the following into typings/index.ts:

type LazyLoader<T> = () => Promise<React.ComponentType<T>>;

and use it in both typings/pages.ts and typings/dashboards.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cant move LazyLoader type to typings/index.ts because that results in a circular dependency. Moved it to typings/types.ts.

@@ -98,7 +98,7 @@ const AppContents = withRouter(React.memo(() => (

<Route path={['/all-namespaces', '/ns/:ns']} component={RedirectComponent} />

<LazyRoute path="/dashboards" exact loader={() => import('./dashboards-page/dashboards' /* webpackChunkName: "dashboards" */).then(m => m.DashboardsPage)} />
<LazyRoute path="/dashboards" loader={() => import('./dashboards-page/dashboards' /* webpackChunkName: "dashboards" */).then(m => m.DashboardsPage)} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @spadgett plugins can add new tabs into existing Dashboards page, with tab ID reflected into the URL.

{
href: '',
name: 'Overview',
component: OverviewDashboard,
},
];

const getCardsOnPosition = (cards: DashboardsCard[], position: GridPosition): React.ComponentType<any>[] =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To render lazy (async) components, you can use Promise-based AsyncComponent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using AsyncComponent now

@vojtechszocs
Copy link
Contributor

My only concern here is to ensure that we load custom components lazily instead of referencing them directly, please see my inline comments for details.

@rawagner
Copy link
Contributor Author

My only concern here is to ensure that we load custom components lazily instead of referencing them directly, please see my inline comments for details.

Thanks @vojtechszocs for review. I addressed all issues, can you take a look again ?

return plugins.registry.getDashboardsTabs().map(tab => {
const tabCards = cards.filter(c => c.properties.tab === tab.properties.id);
return {
href: tab.properties.id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also write an extension check that ensures tab IDs are unique (and non-empty as well), I'll put it on my task list.

In general, every time we add new extension types, we should also consider writing the corresponding extension checks to guard against potential conflicts.

@vojtechszocs vojtechszocs mentioned this pull request Jun 20, 2019
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 20, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 20, 2019
@rawagner
Copy link
Contributor Author

@spadgett can you take a look ?

@cloudbehl
Copy link
Contributor

@spadgett @rawagner Blocked on this PR to be merged. Can we merge this PR?

@jelkosz
Copy link

jelkosz commented Jun 24, 2019

@cloudbehl you should not really be blocked, the API should not change so it is safe to base your work on this already

@cloudbehl
Copy link
Contributor

@jelkosz ok, I was waiting for the PR to be merged. I have raised a dependent PR[1] for now once merged I will rebase it. Thanks

[1]. #1803

@vojtechszocs
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 26, 2019
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rawagner, spadgett, vojtechszocs

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rawagner
Copy link
Contributor Author

/retest

@openshift-merge-robot openshift-merge-robot merged commit 3034dac into openshift:master Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants